package com.medical.medical.controller.manageController;

import com.medical.medical.entity.Department;
import com.medical.medical.entity.Doctor;
import com.medical.medical.service.DepartmentService;
import com.medical.medical.service.doctorManageService.DoctorManageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @ClassName doctorManageController
 * @Description 管理员模块医生信息管理控制层
 * @Author 皮皮虾
 * @Date 2022/9/14 10:58
 * @Version 1.0
 */
@RequestMapping("/doctorManage")
@Controller
@Slf4j
public class DoctorManageController {
    @Resource
    private DoctorManageService doctorManageService;



/*    *//**
     * @description: 获取所有科室
     * @author: Yu
     * @date: 2022/9/24
     * @param model:
     * @return: java.lang.String
     *//*
    @RequestMapping("/ListDepartment")
    public String departmentList(Model model) {

        List<Department> departmentList = departmentService.getDepartmentList();
        model.addAttribute("departmentList", departmentList);
        return "department";
    }*/

/*    *//**
     * @param
     * @description: 查询科室详细信息
     * @author: 皮皮虾
     * @date: 2022/9/14
     * @return:
     *//*
    @RequestMapping("/DepartmentInfo")
    public String listDepartment(Model model,
                                 @RequestParam("departmentId") String departmentId) {
        Department department = doctorManageService.listDepartment(departmentId);
        if (department != null) {
            model.addAttribute(department);
        } else {

        }
        return "depInfo";
    }*/


    /**
     * @param
     * @description: 查询所有医生
     * @author: 皮皮虾
     * @date: 2022/9/14
     * @return:
     */
    @RequestMapping(value = "/listDoctor")
    public String allDoctor(Model model) {
        List<Doctor> doctors = doctorManageService.allDoctor();
        model.addAttribute("doctors",doctors);
        return "doctor/docList";
    }
/**
 * @description: 跳转到添加页面
 * @author: Yu
 * @date: 2022/9/26
 * @param model:
 * @return: java.lang.String
 */
    @RequestMapping(value = "/addPage")
    public String addPage(Model model) {
        return "doctor/addDoc";
    }

    /**
     * @description: 跳转到修改页
     * @author: Yu
     * @date: 2022/9/26
     * @param :
     * @return: java.lang.String
     */
    @RequestMapping(value = "/editDoc")
    public String editDoc() {
        return "doctor/editDoc";
    }
    /**
     * @param
     * @description:根据医生id查询医生详细信息
     * @author: 皮皮虾
     * @date: 2022/9/14
     * @return:
     */
    @RequestMapping("/doctorInfo")
    public String listDoctor(HttpSession session,
                             @RequestParam("dId") String dId) {
        Doctor doctor = doctorManageService.listDoctor(dId);
        System.out.println(doctor);
        log.info("{}",doctor.getDId());
        session.setAttribute("doctorInfo",doctor);
        return "doctor/docInfo";
    }

    /**
     * @param
     * @description:添加医生信息
     * @author: 皮皮虾
     * @date: 2022/9/14
     * @return:
     */
    @RequestMapping("/addDoctor")
    public String addDoctor(@RequestParam("dName") String dName,
                            @RequestParam("dAge") String dAge,
                            @RequestParam("dGender") String dGender,
                            @RequestParam("dDesc") String dDesc,
                            @RequestParam("dPost") String dPost,
                            @RequestParam("registrationFee") String registrationFee,
                            @RequestParam("dHospital") String dHospital,
                            @RequestParam("dAccount") String dAccount,
                            @RequestParam("phone") String phone,
                            @RequestParam("dDepartment") String dDepartment,
                            @RequestParam("password") String password
    ) {
        int i = doctorManageService.addDoctor(dName, dAge, dGender, dDesc, dPost, registrationFee, dHospital, dDepartment,dAccount,phone,password);

        return "redirect:listDoctor";
    }

    /**
     * @param
     * @description:根据医生id修改医生信息
     * @author: 皮皮虾
     * @date: 2022/9/14
     * @return:
     */
    @RequestMapping("/reviseDoctor")
    public String reviseDoctor(@RequestParam("dName") String dName,
                               @RequestParam("dId") String dId,
                               @RequestParam("dAge") String dAge,
                               @RequestParam("dGender") String dGender,
                               @RequestParam("dDesc") String dDesc,
                               @RequestParam("dPost") String dPost,
                               @RequestParam("dHospital") String dHospital,
                               @RequestParam("dDepartment") String dDepartment) {
        int i = doctorManageService.reviseDoctor(dName,dId, dAge, dGender,dDesc,dPost,dDepartment, dHospital);

        return "redirect:listDoctor";
    }

    /**
     * @param
     * @description:根据医生id删除医生信息
     * @author: 皮皮虾
     * @date: 2022/9/14
     * @return:
     */
    @RequestMapping("/delDoctor")
    public String delDoctor(@RequestParam("dId") String dId) {

        int i = doctorManageService.delDoctor(dId);
        return "redirect:listDoctor";
    }
}